﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class GroupVideoDAL : SqlDataProvider
    {
        #region[GroupVideo_GetById]
        public List<GroupVideo> GroupVideo_GetById(string Id)
        {
            List<Entity.GroupVideo> list = new List<Entity.GroupVideo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_GroupVideo_GetById", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(GroupVideo.GroupVideoIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[GroupVideo_GetByTop]
        public List<GroupVideo> GroupVideo_GetByTop(string Top, string Where, string Order)
        {
            List<Entity.GroupVideo> list = new List<Entity.GroupVideo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_GroupVideo_GetByTop", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(GroupVideo.GroupVideoIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[GroupVideo_GetByAll]
        public List<GroupVideo> GroupVideo_GetByAll(string Lang)
        {
            List<Entity.GroupVideo> list = new List<Entity.GroupVideo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_GroupVideo_GetByAll", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(GroupVideo.GroupVideoIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[GroupVideo_Paging]
        public List<GroupVideo> GroupVideo_Paging(string CurentPage, string PageSize, string Lang)
        {
            List<Entity.GroupVideo> list = new List<Entity.GroupVideo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_GroupVideo_Paging", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@CurentPage", CurentPage));
                dbCmd.Parameters.Add(new SqlParameter("@PageSize", PageSize));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(GroupVideo.GroupVideoIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[GroupVideo_Insert]
        public bool GroupVideo_Insert(GroupVideo data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_GroupVideo_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Tag", data.Tag));
                dbCmd.Parameters.Add(new SqlParameter("@Level", data.Level));
                dbCmd.Parameters.Add(new SqlParameter("@Title", data.Title));
                dbCmd.Parameters.Add(new SqlParameter("@Description", data.Description));
                dbCmd.Parameters.Add(new SqlParameter("@Keyword", data.Keyword));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("GroupVideo");
            return true;
        }
        #endregion
        #region[GroupVideo_Update]
        public bool GroupVideo_Update(GroupVideo data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_GroupVideo_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Tag", data.Tag));
                dbCmd.Parameters.Add(new SqlParameter("@Level", data.Level));
                dbCmd.Parameters.Add(new SqlParameter("@Title", data.Title));
                dbCmd.Parameters.Add(new SqlParameter("@Description", data.Description));
                dbCmd.Parameters.Add(new SqlParameter("@Keyword", data.Keyword));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("GroupVideo");
            return true;
        }
        #endregion
        #region[GroupVideo_Delete]
        public bool GroupVideo_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_GroupVideo_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("GroupVideo");
            return true;
        }
        #endregion

    }
}
